home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / demo / demow32s.zip / SOURCE.ZIP / STATETOO.CPP < prev    next >
C/C++ Source or Header  |  1993-04-23  |  6KB  |  199 lines

  1. #include <windows.h>
  2. #include <windowsx.h>
  3. #include <dos.h>
  4. #include <commdlg.h>
  5. #include <shellapi.h>
  6. #include <string.h>
  7. #include "winx31ad.h"
  8. #pragma pack (1)  
  9. #include "statetoo.h"
  10.  
  11. extern HANDLE ghInst;
  12. char szMenuText[128];
  13. static BOOL fIsText = FALSE;
  14. static RECT rectInfo ;
  15. HWND hWndInfo = NULL; 
  16. WORD cxChar,cyChar;
  17.                  
  18. void DoSetInfo(HWND hWnd,LPRECT lpRect)
  19. {
  20. TEXTMETRIC tm;
  21. HDC hdc;
  22.   hWndInfo = hWnd;
  23.   rectInfo = *lpRect;
  24.   hdc = GetDC(hWnd);
  25.   GetTextMetrics(hdc,&tm);
  26.   ReleaseDC(hWnd,hdc);
  27.   cxChar = (WORD)tm.tmMaxCharWidth ;
  28.   cyChar = (WORD)(tm.tmHeight + tm.tmExternalLeading) ;
  29. }                   
  30.  
  31. void DoSetTextInfo(LPSTR lpszTxt)
  32. {            
  33.   if (hWndInfo == NULL) return;
  34.   if (fIsText) InvalidateRect(hWndInfo,&rectInfo,FALSE);
  35.   fIsText = FALSE;
  36.   if (lpszTxt == NULL) return;     
  37.   InvalidateRect(hWndInfo,&rectInfo,FALSE);
  38.   fIsText = TRUE;
  39.   _fstrncpy(szMenuText,lpszTxt,sizeof(szMenuText)-1);
  40.   szMenuText[127] = '\0';
  41. }              
  42.  
  43.  
  44. void DoSetTextResourceInfo(HWND hWnd,UINT idRes)
  45. {
  46.   if (hWndInfo == NULL) return;
  47.   if (fIsText) InvalidateRect(hWnd,&rectInfo,FALSE);
  48.   fIsText = FALSE;
  49.   if (idRes == NULL) return;
  50.   InvalidateRect(hWnd,&rectInfo,FALSE);
  51.   fIsText = TRUE;
  52.   LoadString(ghInst,idRes,szMenuText,sizeof(szMenuText)-1);
  53. }
  54.  
  55. void DoCadre(HDC hdc,UINT left,UINT right,UINT top,UINT bottom,
  56.                                   LPSTR lpTxt,WORD wPct,COLORREF clrref)
  57. {
  58. HBRUSH hBrush;
  59. HPEN hOldPen;
  60. RECT rect;
  61. BOOL fProvDC ; 
  62.      if (hWndInfo == NULL) return;
  63.      fProvDC = (hdc == NULL) ;
  64.      if (fProvDC) hdc = GetDC(hWndInfo);
  65.  
  66.             rect.left=left+1; rect.right=right-1; rect.bottom=bottom+1; rect.top=top-1;
  67.  
  68.             if (wPct == 0)
  69.                 {
  70.                  hBrush=CreateSolidBrush(GetSysColor(COLOR_BTNFACE));
  71.                  FillRect(hdc,&rect,hBrush);
  72.                  DeleteObject(hBrush);
  73.                 }
  74.               else
  75.                 {
  76.                  hBrush=CreateSolidBrush(clrref);
  77.                  rect.right=left+(int)(((right-left)*(DWORD)wPct)/100);
  78.                  FillRect(hdc,&rect,hBrush);
  79.                  DeleteObject(hBrush);
  80.                 }
  81.                 
  82.             rect.left--; rect.right++; rect.top--; rect.bottom++;
  83.             
  84.             if (lpTxt!=NULL)
  85.               {
  86.               HFONT hOldFont ;
  87.               LOGFONT logFont;
  88.  
  89.                SetBkColor(hdc,GetSysColor(COLOR_BTNFACE));
  90.                
  91.                _fmemset(&logFont,0,sizeof(LOGFONT));
  92.                logFont.lfWeight = FW_NORMAL;
  93.                lstrcpy(logFont.lfFaceName,"MS Sans Serif");
  94.                logFont.lfPitchAndFamily = VARIABLE_PITCH | FF_SWISS ;
  95.                logFont.lfHeight = 16;
  96.                hOldFont = SelectObject(hdc,CreateFontIndirect(&logFont));
  97.                TextOut(hdc,cxChar+left,top,lpTxt,lstrlen(lpTxt));
  98.                DeleteObject(SelectObject(hdc,hOldFont));
  99.               }
  100.  
  101.             hOldPen=SelectObject(hdc,
  102.                 CreatePen(PS_SOLID,1,GetSysColor(COLOR_BTNSHADOW)));
  103.             MoveToEx(hdc,left,bottom,NULL);
  104.             LineTo(hdc,left,top);
  105.             LineTo(hdc,right,top);
  106.             DeleteObject(SelectObject(hdc,hOldPen));
  107.  
  108.             hOldPen=SelectObject(hdc,
  109.                 CreatePen(PS_SOLID,1,GetSysColor(COLOR_BTNHIGHLIGHT)));
  110.             MoveToEx(hdc,right,top,NULL);
  111.             LineTo(hdc,right,bottom);
  112.             LineTo(hdc,left,bottom);
  113.             DeleteObject(SelectObject(hdc,hOldPen));
  114.             if (fProvDC) ReleaseDC(hWndInfo,hdc);
  115. }                          
  116.  
  117. void Jauge(HDC hdc,WORD wPct,COLORREF clrref)
  118. {  
  119. BOOL fProvDC ; 
  120.      if (hWndInfo == NULL) return;
  121.      fProvDC = (hdc == NULL) ;
  122.      if (fProvDC) hdc = GetDC(hWndInfo);
  123.  
  124.  
  125. //    DoPeek();
  126.     if (cxChar*1<rectInfo.right-cxChar)
  127.       DoCadre(hdc,cxChar*1,rectInfo.right-cxChar,
  128.                          rectInfo.top+3,rectInfo.bottom-3,
  129.                          NULL,wPct,clrref);
  130.     if (fProvDC) ReleaseDC(hWndInfo,hdc);
  131.  
  132.  
  133.  
  134. void DoPaintInfo (HDC hdc)
  135. {
  136. HBRUSH hBrush;
  137. char szText[40];
  138. //char szRess[40];
  139. RECT rect;
  140. BOOL fProvDC ; 
  141. LPRECT lpRect=&rectInfo;
  142.      if (hWndInfo == NULL) return;
  143.      fProvDC = (hdc == NULL) ;
  144.      if (fProvDC) hdc = GetDC(hWndInfo);
  145.  
  146.             rect = rectInfo;
  147.             rect.top +=2;
  148.             hBrush=CreateSolidBrush(GetSysColor(COLOR_BTNFACE));
  149.             FillRect(hdc,&rectInfo,hBrush);
  150.             DeleteObject(hBrush);
  151.             
  152.  
  153.             SelectObject(hdc,GetStockObject(BLACK_PEN));
  154.             MoveToEx(hdc,lpRect->left,lpRect->top+0,NULL);
  155.             LineTo(hdc,lpRect->right,lpRect->top+0);
  156.  
  157.             SelectObject(hdc,GetStockObject(WHITE_PEN));
  158.             MoveToEx(hdc,lpRect->left,lpRect->top+1,NULL);
  159.             LineTo(hdc,lpRect->right,lpRect->top+1);
  160.             
  161.             if (fIsText)
  162.               {                
  163.               HFONT hOldFont ;
  164.               LOGFONT logFont;
  165.  
  166.                 SetBkColor(hdc,GetSysColor(COLOR_BTNFACE));
  167.                
  168.                 _fmemset(&logFont,0,sizeof(LOGFONT));
  169.                 logFont.lfWeight = FW_NORMAL;
  170.                 lstrcpy(logFont.lfFaceName,"MS Sans Serif");
  171.                 logFont.lfPitchAndFamily = VARIABLE_PITCH | FF_SWISS ;
  172.                 logFont.lfHeight = 16;
  173.                 hOldFont = SelectObject(hdc,CreateFontIndirect(&logFont));
  174.                
  175.                 TextOut(hdc,cxChar,lpRect->top+3,szMenuText,lstrlen(szMenuText));
  176.                 DeleteObject(SelectObject(hdc,hOldFont));     
  177.                 return;
  178.               }
  179.               
  180.             szText[0]='\0';
  181.             
  182.             //DoCadre(hdc,cxChar/2,cxChar*6,lpRect->top+3,lpRect->bottom-3,
  183.             //                                             szText,0,0);
  184.  
  185.             //if (pCurGdb!=NULL)
  186.             //  if (pCurGdb->dwGiveSizeByte() != 0)
  187.             //     wsprintf(szText,"%lu octets",pCurGdb->dwGiveSizeByte());
  188.  
  189.             szText[0]='\0';                                   
  190.             //DoCadre(hdc,cxChar*6+(cxChar/2),cxChar*17+(cxChar/2),lpRect->top+3,lpRect->bottom-3,
  191.             //           szText,0,0);
  192.                        
  193.                        
  194.            
  195.             Jauge(hdc,0,0);
  196.             if (fProvDC) ReleaseDC(hWndInfo,hdc);
  197. }
  198.